home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / YERK / SUPPLEME / MY_STUFF / PMENU.EXA < prev    next >
Text File  |  1991-01-01  |  2KB  |  61 lines

  1. \    rfl    sample code as popUp menu example
  2. \        because the popup has an associated hmenu, we can't use 'getpmtxt'
  3.  
  4.  0 constant left
  5.  1 constant center
  6. -1 constant right
  7.  
  8. \ simple subclass of rectangle to bring up pmenu
  9. :CLASS popUpRect <super rect
  10.  
  11.     int    just
  12.     string    myName
  13.  
  14.   :M new: new: myName ;M
  15.  
  16.   :M justify: put: just ;M
  17.  
  18. \ is point x y inside this rectangle?
  19.   :M ptIn: { x y -- b } word0 x y pack (abs) call ptInRect i->l ;M
  20.  
  21.   :M print: ( addr len -- ) put: myName 1 1 inset: self
  22.         ptr: myName +base size: myName (abs) int: just call textBox
  23.         -1 -1 inset: self ;M
  24.  
  25.   :M draw: draw: super get: myName print: self ;M
  26.  
  27.   :M release: release: myName ;M
  28.  
  29. ;CLASS
  30.  
  31.  
  32. window MyWind    \ instantiate a window
  33.  
  34. 5 pMenu myPMenu    \ instantiate a popUpMenu
  35. 2 hMenu myHMenu    \ instantiate a hierarchical Menu
  36.  
  37. popUpRect myPRect    \ instantiate a rectangle to click in
  38.  
  39. new: myPRect    \ get a handle
  40. left justify: myPRect
  41. 20 50 120 68 put: myPRect
  42.  
  43. \ menu handlers
  44. : one  home mitem . mitem get: myPmenu print: myPRect ;
  45. : five  home mitem 4+ . mitem get: myHMenu print: myPRect ;
  46.  
  47. \ this will be executed when the mouse is clicked inside myPRect
  48. \  Could make class popUpRect a bit more intelligent, storing the pMenu
  49. \  as an IVAR...
  50. : popUp where: theMouse ptIn: myPRect IF popUp: myPMenu THEN ;
  51.  
  52. : drawR -curs 0 tfont 12 tsize draw: myPRect ;
  53. 4 'cfas null null drawR popUp actions: myWind
  54.  
  55. \ get an example of myWind
  56. example: myWind
  57.  
  58. \ load the menu...make sure it is in the search pathlist.
  59. " Pmenu.txt" getMTxt
  60.  
  61.